import math
import random
import time
'''Check a fibonancci number '''
def is_fibo(n):
    phi = 0.5 + 0.5 * math.sqrt(5.0)
    a = phi * n
    return n == 0 or abs(round(a) - a) < 1.0 / n
'''Coroutine Decorator '''
def coroutine(func):
    def start(*args, **kwargs):
        cr = func(*args, **kwargs)
        cr.next()
        return cr
    return start
''' producer function'''
def producer():
    time.sleep(1)
    r = random.randint(1, 1000)
    pro = consumer(r)
    pro.send(r)

'''Consumer function'''
@coroutine
def consumer(rand):
    print "Check ", rand
    while True:        
        number = (yield)
        if is_fibo(number):
            print "%d is fibonacci number\n" % number
        else:
            print "%d isn't fibonacci number\n" % number
                
'''Main for running'''
while True:
    producer()
